/**
 * Created by AMD on 29.10.14.
 */
package {


import InterfaceObjects.BottomPanel.BottomPanel;
import InterfaceObjects.OrdetProductWindow.OrderProductWindow;

import components.CashDeskComponent;
import components.ShelfComponent;
import components.ShopperComponent;

import controller.DebugConsoleCommand;

import controller.DebugErrorCommand;
import controller.GameLayerTouchCommand;
import controller.InterfaceLayerTouchCommand;
import controller.OnSecondPassedCommand;
import controller.ShopperActionCommand;
import controller.TestCommand;
import controller.UnpackShopDesignCommand;
import controller.UnpackShopObjectsCommand;
import controller.UnpackWarehouseDataCommand;
import controller.UserLevelChangedCommand;

import layers.GameLayer;
import layers.InterfaceLayer;

import messages.DebugMessage;
import messages.ModelToControllerMessage;
import messages.ModelToViewMessage;
import messages.ViewToControllerMessage;

import model.LocalizationProxy;

import model.MainProxy;
import model.PrototypeProxy;
import model.RuntimeProxy;

import model.UserProxy;
import model.WarehouseDataProxy;

import mvcexpress.core.MediatorMap;
import mvcexpress.modules.ModuleCore;
import mvcexpress.utils.checkClassStringConstants;

import view.BottomPanelMediator;

import view.CashDeskComponentMediator;

import view.GameLayerMediator;
import view.InterfaceLayerMediator;

import view.MainMediator;
import view.OrderProductWindowMediator;
import view.ShelfComponentMediator;
import view.ShopperComponentMediator;

public class MvcMainModule extends ModuleCore{
    private var _warehouseDataProxy:WarehouseDataProxy;
    private var _userProxy:UserProxy;
    private var _prototypeProxy:PrototypeProxy;
    private var _runtimeProxy:RuntimeProxy;
    private var _localizationProxy:LocalizationProxy;


    //mac comment #3

     override protected function onInit():void {
         trace("MainModule.onInit");
         mediatorMap.map(StarlingMain,MainMediator);
         mediatorMap.map(InterfaceLayer,InterfaceLayerMediator);//Interface Layer
         mediatorMap.map(BottomPanel,BottomPanelMediator);
         mediatorMap.map(OrderProductWindow,OrderProductWindowMediator);
         mediatorMap.map(GameLayer,GameLayerMediator);          //Game Layer
         mediatorMap.map(ShelfComponent, ShelfComponentMediator);
         mediatorMap.map(CashDeskComponent, CashDeskComponentMediator);
         mediatorMap.map(ShopperComponent, ShopperComponentMediator);



         commandMap.map(ViewToControllerMessage.MAIN_ORANGE_BUTTON_CLICKED,TestCommand);
         commandMap.map(ViewToControllerMessage.GAME_LAYER_TOUCH,GameLayerTouchCommand);
         commandMap.map(ViewToControllerMessage.INTERFACE_LAYER_TOUCH,InterfaceLayerTouchCommand);
         commandMap.map(ViewToControllerMessage.ONE_SECOND_TIMER_FROM_MEDIATOR,OnSecondPassedCommand);
         commandMap.map(ViewToControllerMessage.SHOPPER_NEED_ACTION,ShopperActionCommand);

         commandMap.map(ModelToControllerMessage.USER_SHOP_OBJECTS_LOADED,UnpackShopObjectsCommand);
         commandMap.map(ModelToControllerMessage.SHOP_DESIGN_LOADED,UnpackShopDesignCommand);
         commandMap.map(ModelToControllerMessage.USER_WAREHOUSE_DATA_INPUT,UnpackWarehouseDataCommand);
         commandMap.map(ModelToControllerMessage.USER_LEVEL_CHANGED,UserLevelChangedCommand);

         commandMap.map(DebugMessage.ERROR_MESSAGE,DebugErrorCommand);
         commandMap.map(DebugMessage.CONSOLE_COMMAND,DebugConsoleCommand);
         //commandMap.map(ViewMessage.MAIN_ORANGE_BUTTON_CLICKED2,TestCommand2);




         this._localizationProxy = new LocalizationProxy()
         proxyMap.map(this._localizationProxy);

         this._prototypeProxy = new PrototypeProxy();
         proxyMap.map(this._prototypeProxy);

         this._warehouseDataProxy = new WarehouseDataProxy();
         proxyMap.map(this._warehouseDataProxy);

         this._userProxy = new UserProxy(this._warehouseDataProxy);
         proxyMap.map(this._userProxy);

         this._runtimeProxy = new RuntimeProxy()
         proxyMap.map(this._runtimeProxy);

         //proxyMap.map(_mainProxy,null,null,MainProxy);

     }

    public function start(main:StarlingMain):void {
        trace("MainModule.start > main : " + main);
        mediatorMap.mediate(main);
        trace("Hello mvcExpress!!!");

        this._fillTestData();

    }

    private function _fillTestData():void {
        //------------------------------------
        //localization must be loaded FIRST!!!
        //-------------------------------------
        this._localizationProxy.localization = {
            order_product_window:{
                title:"Order product",
                tab1:"Products",
                tab2:"Tech",
                tab3:"Home",
                tab4:"Other"
            },
            products:{
                p1:"Water",
                p2:"Bananas",
                p3:"Tooth paste"
            },
            shelfPrototypes:{
                s_1:"Basic Cash Desk"
            },
            shopObjectPrototypes:{
                d_1:"Basic Cash Desk"
            }

        }

        //----------------------------------------


        //field 'extra' is for making more fields by replacing pattern 'extra:""' with 'new_field:"someValue", extra""'
        //occ_matrix -  "0" - reserved ;  "1" - occupied ; "-1" - free
        this._prototypeProxy.shelfsPrototype = {
            s_1:{sprite_id:"Shelf1",price:"10g", part_volume:"2000", parts_num:"2", level:"1",occ_matrix:"[[-1,-1,-1],[0,1,0],[0,0,0]]", extra:""},
            s_2:{sprite_id:"Shelf2",price:"8g", part_volume:"3000", parts_num:"1", level:"1",occ_matrix:"[[-1,-1,-1],[0,1,0],[0,0,0]]", extra:""}
        };

        //field 'extra' is for making more fields by replacing pattern 'extra:""' with 'new_field:"someValue", extra""'
        //occ_matrix -  "0" - reserved ;  "1" - occupied ; "-1" - free
        this._prototypeProxy.shopObjectPrototypes = {
            d_1:{price:"15g",sprite_id:"CashDesk1", disabled_sides:"135,225", level:"1",occ_matrix:"[[-1,-1,-1,-1,0],[0,-1,1,-1,0],[0,-1,1,-1,0],[0,-1,1,-1,0],[0,-1,-1,-1,0]]", extra:""}
        }

        //field 'extra' is for making more fields by replacing pattern 'extra:""' with 'new_field:"someValue", extra""'
        this._prototypeProxy.productsPrototype = {
            p1:{ sprite_id:"Water_1",level:"1", price:"1g", group:"1", volume:"500", demand:"30",deliver:"10", exp:"144", extra:""},
            p2:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p3:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p4:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p5:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p6:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p7:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p8:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p9:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p10:{ sprite_id:"Banana",level:"1", price:"1g", group:"1",volume:"120", demand:"20",deliver:"5", exp:"72", extra:""},
            p11:{ sprite_id:"ToothPaste",level:"1", price:"1g", group:"1", volume:"30",demand:"20",deliver:"3", exp:"72", extra:""}
        };

        this._prototypeProxy.floorsPrototype = {
            f_1:{ sprite_id:"Floor1", cost:"1g", level:"1"},
            f_2:{ sprite_id:"Floor2", cost:"1g", level:"1"},
            f_3:{ sprite_id:"Floor3", cost:"1g", level:"1"}
        }
        this._prototypeProxy.wallsPrototype = {
            w_1:{ sprite_id:"Wall1", cost:"1g", level:"1"},
            w_2:{ sprite_id:"Wall2", cost:"1g", level:"1"},
            w_3:{ sprite_id:"Wall3", cost:"1g", level:"1"}
        }


        this._runtimeProxy.currentTime = 1926951461;

        _userProxy.level = 1;

        _userProxy.warehouseDataProxy.shortData = {
            size:6*2,
            volume:2000,
            items:"p1x200d1926951861|null||p2x100d1926951461|p2x10d1926951461"
        }

        _userProxy.shopDesignPacked = {
            sizeX:"10",sizeY:"8",
            floors:{x5y6:"2",x0y0:"2", std:"Floor1"},
            walls:{x1:"2", y2:"3", y4:"3", std:"Wall1"},
            doors:{x1:"1",y1:"1"},//, x3:"1", y2:"1"},
            covers:{x0:"wnd_1",x5:"wnd_1",y4:"wnd_1"}  //wall covers (windows, etc)
        };
        // !!!!ready!!!!
        //make same as _userProxy.shopObjectsPacked  ===> command ===> runtimeProxy ====> view
        //-------------------------------------

        _userProxy.shopObjectsPacked = {
            x1y1:"s_1|135|p1x2e123456789,p2x2e123456789",
            x2y5:"d_1|225|null",
            //x4y4:"s1|225|p2x25e123456789,p3x35e123456789",
            //x5y4:"s1|225|p2x25e123456789,p3x35e123456789",
            x4y2:"s_1|225|p2x25e123456789,p3x35e123456789",
            x5y2:"s_1|225|p2x25e123456789,p3x35e123456789",
            //x6y2:"s_1|225|p2x25e123456789,p3x35e123456789",
            x7y2:"s_1|225|p2x25e123456789,p3x35e123456789",
            x8y2:"s_1|225|p2x25e123456789,p3x35e123456789",

            x4y4:"s_1|225|p2x25e123456789,p3x35e123456789",
            x6y4:"s_1|225|p2x25e123456789,p3x35e123456789",
            x7y4:"s_1|225|p2x25e123456789,p3x35e123456789",
            x8y4:"s_1|225|p2x25e123456789,p3x35e123456789",

            x4y6:"s_1|225|p2x25e123456789,p3x35e123456789",
            x5y6:"s_1|225|p2x25e123456789,p3x35e123456789",
            x6y6:"s_1|225|p2x25e123456789,p3x35e123456789",
            //x7y6:"s_1|225|p2x25e123456789,p3x35e123456789",
            x8y6:"s_1|225|p2x25e123456789,p3x35e123456789"
        };

        // !!!!ready!!!!
        //_userProxy.shopObjectsSettingPacked change ====>>  unpack command ====[upd by single cell or complex upd]====>>
        // runtimeProxy gameField change ====[single cell or complex]====>> GameLayerMediator change
        //--------------------------------------




        //_userProxy.shopObjectsPacked = _userProxy.shopObjectsPacked;
    }
}
}
